!pr0
!lm12
!rm75
Using Auxiliary Memory in the //e.............David C. Johnson
                                               Ridgefield, CT

When I bought my Apple //e (3 days after they became available!), I also got the Extended 80-Column Text Card.  I wanted it both to have 80 column text capability and a full complement of Apple Computer Inc. supported memory.  However, Apple only supplied two small subroutines in ROM and incomplete (but otherwise excellent) documentation in their manuals, in "support" of the auxiliary memory.

I say "incomplete" because two I/O locations that I used in my program are not mentioned (in English anyway) anywhere in the manuals except in the listings of the 80-column firmware. The two I/O locations are $C011 & $C012 which I call READ.BSR.BANK & READ.BSR.RAM.READ. Apple evidently intends to let software developers determine how the auxiliary memory is to be used.

Well here goes:  my program is called "USE.AUXMEM".  This program allows you to access the "other" 64K in a manner most Apple users should already be familiar with:  monitor commands.

The simplest way to see what I mean is to type in & assemble the program (not so simple), type :"MGO G", :"PR#3" and then :"$^Y" (that is control-Y).  You will get a bell and the monitor's prompt.  Any monitor commands you type now will "use" the auxiliary memory.  Try these now:

       *3D0:55
       *3D0     (double nickels, right?)
       *^Y      (back to SCASM!)
       :$3D0    (a $4C!)

You should note that control-Y while using the auxiliary memory returns to main memory with everything as it was.  Now try these:

       :$^Y 3D0
       *3D0 ^Y

After the second control-Y returned to main memory, SCASM finished the first command line!

The reason I had you type :"PR#3" before is quite simple:  things don't all work right without the 80 column firmware active; specifically, right-arrow & escape functions.  You can also type "escape 4" if you don't want 80 columns.

But wait a minute, if you read the 80-column firmware listing (carefully), you know that it does NOT work with the auxiliary memory enabled (as doesn't the regular 40-column firmware), so how is this all working?  Well, the I/O hooks in the auxiliary memory zero page point to routines in USE.AUXMEM which switch to main memory, perform the I/O, switch back to auxiliary memory, and return to the monitor. The monitor executes its commands between I/O calls while auxiliary memory is enabled. These switchings also change the bank switched memory state.

The USE.AUXMEM program has two other control-Y commands. They implement the crossbank subroutines AUXMOVE & XFER (supplied in ROM) as monitor commands. See the comments at the top of the source listing for their syntax.


About Some //e Monitor Bugs...

One routine, USE.AUXMEM.CONTROL.Y.HANDLER, deserves a special note.  It compensates for a bug in the Apple //e version of the monitor:  when parsing a control-Y command the ASCII string "Bryan" at $FEC5 is executed as instructions prior to JMPing to USRADR ($03F8). This bug has a long history.

In the original Apple monitor the CHRSRCH loop ($FF78 - $FF81) scans the CHRTBL ($FFCC - $FFE2) from end to beginning, which matches the $B2 at $FFCD causing TOSUB ($FFBE - $FFCB) to load the $C9 at $FFE4 and RTS to USR ($FECA) which is a JMP USRADR ($03F8).

Things started to go astray when the autostart ROM was created, and the Apple II Plus.  To make room for new features, (like printing "APPLE ][" at the top of the screen on power up, and like the escape-IJKM cursor motion), the TRACE and STEP commands were removed.  To disable the entries for Trace and Step in CHRTBL, the bytes for "T" and "S" were changed:  ($FFCF:B2 & $FFD2:B2, also $FFE9:C4). Locations $FEC5 - $FEC9, immediately prior to USR, were changed to NOPs.

Unfortunately, someone forgot that CHRTBL is searched from end to beginning, causing a control-Y command to be matched with the $B2 at $FFD2, corresponding to the branch address in SUBTBL at $FFE9.  So when you type a control-Y command the monitor branches to $FFC5 and executes the 5 NOPs.  If $FFE9 had been changed to $C9 instead of $C4, everything would have still been fine.

Executing 5 NOPs is not a bad bug.  But when the Apple //e monitor was created those 5 NOPs were replaced by the string "Bryan".  In hex it is C2 F2 F9 E1 EE.  The 6502 instruction set does not include a definition for $C2, but after a little investigation, or after reading Bob Sander-Cederlof's article in AAL March 1981, you find out that $C2 acts like a two-byte NOP.  The "r" is skipped over.  The "yan", however, is a SBC $EEE1,Y instruction.

The USE.AUXMEM.CONTROL.Y.HANDLER uses the passed contents of the A & X registers to decide which of the three control-Y commands you've typed.  The SBC $EEE1,Y changes the A register so its contents must be reconstructed.  The reconstruction is further complicated by the fact that the monitor leaves the carry flag set when it RTS's to $FEC5, while the S-C Assembler and Mini-Assembler leave the carry flag clear.

To restore the A register to its proper value you must set the carry to the complement of the value that it was set to prior to the SBC $EEE1,Y then execute ADC $EEE1,Y.

The Apple //e 80 column firmware also contains a bug.  Because of the $11 at $C92A, the key sequence "ESCape ^L" causes a RTS to $4CCE.  Location $C92A should contain a $10.  This bug can be used to advantage if you feel like adding a secret command to your own software.  Just be certain you have the code for your command starting at $4CCE, and that you are running in 80-column mode.  Then whenever you type control-L in the escape mode (cursor is an inverse plus) your code will be executed.

I hope all of you enjoy using your auxiliary memory as much as I do.

Last Minute Note:  David just called to report yet another oddity in the //e ROMs.  In 40-column ESCape mode the (, 5, *, and + keys duplicate the arrow keys.  That is, "ESC 5" moves the cursor right one space, just like ESC right arrow.  This is a little bit weird, but it doesn't seem to hurt anything.  The effect is caused by an unnecessary AND #$DF instruction at $C26E.
